<?php

class User_Form_UserUpdate extends Zend_Dojo_Form
{
    public function init()
    {    	
        $this->setName("UserAdd");
        $this->setMethod('post');
        $this->setOptions(array('onSubmit'=>"return(validateForm(this))"));
        
        $id = new Zend_Form_Element_Hidden('id');
        $id->addFilter('Int');
        
        $this->addElement('TextBox', 'username',array(        
	        'label'          => 'Usuário: ',
         	'focus'          => false,
	        'required'       => false,
	        'regExp'         => '[\w]+',
	        'invalidMessage' => 'Usuário inválido',
        	'style'      	 => 'width: 250px;',
       	 	'disabled'      	 => true,
        ));
        
		$this->addDisplayGroup(array('username'), 'basicos', array('legend'=>"Dados básicos")); 

		//----------------------------------------------------------------------------------

        $this->addElement('ValidationTextBox', 'fullname',array(        
	        'label'          => 'Nome completo: ',
	        'required'       => true,
	        'invalidMessage' => 'Nome inválido',
        	'style'      	 => 'width: 400px;',
        ));

         $this->addElement('ValidationTextBox', 'alias',array(        
	        'label'          => 'Apelido: ',
	        'required'       => false,
	        'invalidMessage' => 'Usuário inválido',
        	'style'      	 => 'width: 250px;',
        ));

        
        $this->addDisplayGroup(array('fullname', 'alias'), 'complementar', array('legend'=>"Dados complementares"));
        
        
        //----------------------------------------------------------------------------------

		//Sectors
		$sectorDbTable = new Admin_Model_Sectors();
		$sectors = $sectorDbTable->getSectors();
		$sectorOptions[null] = '';
		foreach ($sectors as $key => $val) {
			$organsDbTable = new Admin_Model_Organs();
			$organ = $organsDbTable->getOrganById($val['id_organ']);
			$sectorOptions[$val['id']] = $organ['acronym'].'-'.$val['name'];
		}

		$form = $this->addElement('ComboBox', 'id_sector', array (
			'label' => 'Setor: ',
			'value' => 'id_sector',
			'style' => 'width: 400px;',
			'required' => true,
			'autocomplete' => true,
			'multiOptions' => $sectorOptions
		));
		
		//Crafts
		$craftDbTable = new Admin_Model_Crafts();
		$crafts = $craftDbTable->getCrafts();
		$craftOptions[null] = '';
		foreach ($crafts as $key => $val) {
			$craftOptions[$val['id']] = $val['description'];
		}

		$form = $this->addElement('Select', 'id_craft', array (
			'label' => 'Cargo: ',
			'value' => 'id_craft',
			'style' => 'width: 200px;',
			'required' => true,
			'multiOptions' => $craftOptions
		));

		$this->addDisplayGroup(array (
			'id_sector',
			'id_craft'
		), 'cargo', array (
			'legend' => "Cargo e setor"
		));		
		
		//----------------------------------------------------------------------------------

        $this->addElement('ValidationTextBox', 'email',array(        
	        'label'          => 'E-Mail: ',
	        'required'       => true,
       		'regExp'         => '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$',
	        'invalidMessage' => 'E-Mail inválido',
        	'style'      	 => 'width: 400px;',
        ));

         $this->addElement('ValidationTextBox', 'phone',array(        
	        'label'          => 'Telefone: ',
	        'required'       => false,
	        'invalidMessage' => 'Usuário inválido',
        	'style'      	 => 'width: 250px;',
        ));

        
        $this->addDisplayGroup(array('email', 'phone'), 'contato', array('legend'=>"Contato"));
        
        
        //----------------------------------------------------------------------------------
        
        $this->addElement('SubmitButton', 'insert', array(
            'label'    => 'Salvar',
	        'required' => true,
	        'ignore' => false,
        ));

    }
}

